<?php
namespace App\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
class UserRequest extends FormRequest{



    public function authorize()
    {
        return true;
    }


    //验证规则
    protected $rules = [
        'account' => 'required|between:3,16',
        //'password' => 'required',

    ];




    public function messages() {
        return  [
            'account.required' => '请输入账号',
            'account.between' => '用户名在3到12位之间',
            'password.min'=> '密码最少长度为:min',
            'password.required' => '密码不能为空',
            'account.unique' => '账号已经存在、不能重复、请重新填写',
            'agent_name.required'=> '请输入代理商名称',
            'agent_name.min'=> '代理商名称最少长度为:min',
            'company_name.required'=>'请输入所属公司',
            'company_name.min'=>'所属公司最少长度为:min',
            'store_num.required'=>'请输入平台数量',
            'expiration_time.required'=>'请输入过期时间',
            'phone.required'=>'请输入手机号码',
            'user_id.required'=>'代理商不存在',




        ];

    }


    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {

        $rules = $this->rules;

        if (Request::getPathInfo() == '/adminapi/login')//如果是login方法
        {

            $rules['password'] = 'required|min:6';
        }
        if (Request::getPathInfo() == '/adminapi/agent/add' || Request::getPathInfo() == '/adminapi/agent/update'){  //代理商创建
            $rules['pwd'] = 'required|min:6';
            /*  $rules['agent_name'] = 'required|min:2';*/
            /*   $rules['company_name'] = 'required|min:3';
               $rules['store_num'] = 'required';*/
            $rules['expiration_time'] = 'required';
            $rules['phone'] = 'required';
        }
        if (Request::getPathInfo() == '/adminapi/agent/update_scnum'){  //代理商设置短信次数合同词次数
            $rules['user_id'] = 'required';


        }
        return $rules;

    }




}













































